package com.lgkj.adapter;

import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cb.ratingbar.CBRatingBar;
import com.lgkj.R;
import com.lgkj.bean.BarbershopBean;
import com.lgkj.ui.ImageBrowseActivity;
import com.lgkj.utils.CommonUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/7/3 0003.
 */

public class HairStyleHomeAdapter extends BaseAdapter {
    private Context context;

    private List<BarbershopBean.DataBean.BarbersBean> data;


    public void setData(List<BarbershopBean.DataBean.BarbersBean> datas) {
        if (datas != null) {
            this.data = datas;
        }
    }

    public HairStyleHomeAdapter(Context context) {
        this.context = context;
        this.data = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.hair_style_item, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        CommonUtils.LoadImage(context, viewHolder.ivPhoto, data.get(i).getBarber_img(), R.mipmap.hair_style_user_phot);
        viewHolder.ib_del.setVisibility(View.GONE);
        viewHolder.tvName.setText(data.get(i).getBarber_name());
        viewHolder.tvDaoshi.setText(data.get(i).getBarber_name());

        viewHolder.ivPhoto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Activity activity = (Activity) context;
                String url = data.get(i).getBarber_img();
                Intent intent = new Intent(context, ImageBrowseActivity.class);
                intent.putExtra("image_url", url);
                context.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(activity, view, "shareNames").toBundle());
            }
        });
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.ib_del)
        ImageView ib_del;
        @BindView(R.id.iv_photo)
        ImageView ivPhoto;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_daoshi)
        TextView tvDaoshi;
        @BindView(R.id.rb_favour)
        CBRatingBar rbFavour;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
